1 00:00:00,440 --> 00:00:04,480 Now that I have a minefield sign, let's go ahead and create a minefield. 2 00:00:04,490 --> 00:00:10,200 I'm going to use code to populate the minefield by randomly putting mines around the sign. 3 00:00:10,220 --> 00:00:12,460 Let's go to our workspace. 4 00:00:12,470 --> 00:00:18,020 Hit the plus, add a folder and I'm going to call this mines. 5 00:00:18,020 --> 00:00:24,440 So when I clone and spawn a mine, I'm going to put it in this folder so I can keep track so I know 6 00:00:24,440 --> 00:00:25,970 how many there are going to be. 7 00:00:26,210 --> 00:00:26,720 All right. 8 00:00:26,720 --> 00:00:29,540 Now I'm going to go down to my server storage. 9 00:00:29,540 --> 00:00:31,100 I'm going to look at the landmine. 10 00:00:31,100 --> 00:00:36,710 We did this earlier in the course and I have a few things in the landmine model. 11 00:00:36,710 --> 00:00:38,840 You can open and shut it right here. 12 00:00:38,840 --> 00:00:44,720 I want to select a primary part from my landmine because I'm moving it with code, so I'm going to go 13 00:00:44,720 --> 00:00:52,790 down to primary part, click here in the box to the right of where it says primary part, select a primary 14 00:00:52,790 --> 00:00:53,360 part. 15 00:00:53,360 --> 00:00:58,910 You used to have to do that or you get an error when you tried to move it with code using the move to. 16 00:00:58,910 --> 00:01:02,570 Now, I think it's selects a random one if you don't do that. 17 00:01:02,570 --> 00:01:05,450 But I like to know what the primary part is. 18 00:01:07,030 --> 00:01:10,000 All right, now let's go to server script service. 19 00:01:10,030 --> 00:01:14,680 Open up our session utils in session utils. 20 00:01:14,680 --> 00:01:18,460 Let's get a reference to our minds folder. 21 00:01:19,090 --> 00:01:21,520 I'll make a variable local. 22 00:01:22,090 --> 00:01:23,290 I'll just call it with notes. 23 00:01:23,290 --> 00:01:28,510 Mine folder, workspace mines. 24 00:01:28,840 --> 00:01:34,060 Also, I want to know where that sign is and then put the minds close to the sign. 25 00:01:34,060 --> 00:01:34,600 Right. 26 00:01:34,600 --> 00:01:37,140 That's the whole point of having a sign for a minefield. 27 00:01:37,150 --> 00:01:40,240 So I just need the sign position. 28 00:01:40,240 --> 00:01:41,860 I don't really need the sign. 29 00:01:41,860 --> 00:01:44,440 I'm going to need to get the sign for the position, though. 30 00:01:44,440 --> 00:01:48,490 So I'll say Workspace landmine sign. 31 00:01:48,490 --> 00:01:51,880 I'm going to get the post because that's the part that sticks in the ground. 32 00:01:52,150 --> 00:01:53,350 I say position. 33 00:01:54,010 --> 00:01:54,600 Cool. 34 00:01:54,610 --> 00:02:01,090 One more variable local is a debris gain. 35 00:02:01,120 --> 00:02:03,400 Get service debris. 36 00:02:03,400 --> 00:02:04,810 What does this do? 37 00:02:04,810 --> 00:02:07,510 This marks things with a time to live. 38 00:02:07,510 --> 00:02:11,080 I'm going to be cloning minds, so I'm going to give them a time to live. 39 00:02:11,080 --> 00:02:13,450 Let's say 5 to 10 minutes or something. 40 00:02:13,450 --> 00:02:18,760 They'll disappear and then we'll put a new mine down, keep some randomness in our minefield. 41 00:02:20,030 --> 00:02:21,290 Under my start wave. 42 00:02:21,290 --> 00:02:24,830 I'm going to make a function to place my mines in the mine field. 43 00:02:24,860 --> 00:02:26,240 I'm not going to say local. 44 00:02:26,240 --> 00:02:31,250 I'm just going to start with function because I'm going to call this from my wave loop and I'll need 45 00:02:31,250 --> 00:02:35,000 that utils prepend in place minds. 46 00:02:35,000 --> 00:02:39,050 I'm going to pass in my desired number of mines. 47 00:02:39,050 --> 00:02:43,910 None of mine's I'll move my mouse so you can see. 48 00:02:43,910 --> 00:02:47,060 And then the distance is going to be the distance from the sign. 49 00:02:47,060 --> 00:02:53,720 So basically how big my mind field is going to be, I'm going to need a variable for my mind. 50 00:02:53,720 --> 00:02:55,340 It's internet and server storage. 51 00:02:55,340 --> 00:03:00,230 I'm going to call this TX mine for template mine server storage. 52 00:03:00,230 --> 00:03:05,690 That's the variable for server storage as wait for child landmine. 53 00:03:06,530 --> 00:03:10,040 Now I also want the count. 54 00:03:10,550 --> 00:03:14,450 I want to know how many minds I have in my mind folder at any given time. 55 00:03:14,450 --> 00:03:18,050 We're going to start out with zero, but at some point we might have like five. 56 00:03:18,080 --> 00:03:20,180 Maybe we want to have like ten. 57 00:03:20,180 --> 00:03:21,890 So we need to keep track. 58 00:03:21,890 --> 00:03:28,430 So we'll say count equals the number of mine folder. 59 00:03:28,430 --> 00:03:31,580 Get children elements, right? 60 00:03:32,090 --> 00:03:36,470 So there's five mines in our folder, count will be five. 61 00:03:36,680 --> 00:03:47,150 I'm going to do a for loop for I equals count plus one up to the number of mines and steps of one. 62 00:03:48,230 --> 00:03:48,370 Right. 63 00:03:48,530 --> 00:03:54,410 So if we have five mines but we want ten, this is going to start out at six and it's going to go to 64 00:03:54,410 --> 00:03:54,740 ten. 65 00:03:54,740 --> 00:03:56,300 So we'll do five loops. 66 00:03:56,300 --> 00:03:58,640 We're going to clone five new mines. 67 00:03:58,640 --> 00:04:01,670 We need the location of where we're going to put those mines. 68 00:04:01,670 --> 00:04:04,070 I'm going to do some random number generation. 69 00:04:04,070 --> 00:04:15,710 So X rand, we have a random number generator called R and D, we'll say next int minus dist to dist. 70 00:04:15,710 --> 00:04:22,160 So if this is 5050 studs, it's going to give you a number between -50 and 50. 71 00:04:22,520 --> 00:04:23,870 We're going to do another one. 72 00:04:23,870 --> 00:04:35,090 Woops, there we go for the Z z rand rand next integer minus dist to dest. 73 00:04:35,390 --> 00:04:36,020 Cool. 74 00:04:36,020 --> 00:04:40,610 Now the Y, I'm just going to use the Y from my TX mine. 75 00:04:40,610 --> 00:04:43,190 So we are assuming a flat ground. 76 00:04:43,190 --> 00:04:49,370 If you have complex terrain, then you're going to have to find out what your y value is. 77 00:04:49,370 --> 00:04:55,760 You might even have to do something like in the spawn zombies and make spawn locations for your mines. 78 00:04:55,760 --> 00:04:57,830 I'm just showing you a different way here. 79 00:04:57,830 --> 00:05:04,160 So now what I'm going to do is I'm going to get a position that's going to have the three numbers that 80 00:05:04,160 --> 00:05:04,780 I want. 81 00:05:04,790 --> 00:05:06,890 I'm going to put this in a vector three. 82 00:05:07,010 --> 00:05:09,110 You have to do a vector three new. 83 00:05:09,110 --> 00:05:21,830 I'm going to have my x rand, but I'm going to use my sign position dot x plus my x rand value to my 84 00:05:21,830 --> 00:05:23,510 TX mine. 85 00:05:23,720 --> 00:05:24,950 We have a plate. 86 00:05:24,950 --> 00:05:26,810 That's the primary part. 87 00:05:26,810 --> 00:05:32,210 The plate has a position, the position has a y value. 88 00:05:32,210 --> 00:05:35,240 So that's where I got my Y from, from the template. 89 00:05:35,600 --> 00:05:41,180 Then I'm going to get my sign position Z plus z. 90 00:05:41,210 --> 00:05:43,160 Oops, that's an x z. 91 00:05:43,940 --> 00:05:45,050 Oh my gosh. 92 00:05:45,050 --> 00:05:46,700 Z rand. 93 00:05:47,510 --> 00:05:48,730 Who dies a lot. 94 00:05:48,740 --> 00:05:50,030 I know that was kind of tricky. 95 00:05:50,030 --> 00:05:52,490 So I put this on a new line just so you can see it. 96 00:05:52,490 --> 00:05:54,080 You can keep it all on one line. 97 00:05:55,280 --> 00:05:56,330 There we go. 98 00:05:56,480 --> 00:06:02,030 So if you get like your minds in a line or something, you're going to know that you messed up one of 99 00:06:02,030 --> 00:06:02,710 these, right? 100 00:06:02,720 --> 00:06:04,400 Start checking out that stuff. 101 00:06:04,760 --> 00:06:05,180 All right. 102 00:06:05,180 --> 00:06:06,410 So we've got our position. 103 00:06:06,410 --> 00:06:08,030 We still haven't cloned our mind. 104 00:06:08,030 --> 00:06:10,230 So let's go ahead and make a variable called mine. 105 00:06:10,250 --> 00:06:13,220 We'll get our TX mine will clone it. 106 00:06:14,090 --> 00:06:15,950 Let me move this up so you can see it. 107 00:06:15,950 --> 00:06:23,450 And then the mine's parent is going to be the folder, right? 108 00:06:23,450 --> 00:06:24,740 The mine folder. 109 00:06:24,740 --> 00:06:26,660 We want to put the mine in the mine folder. 110 00:06:26,660 --> 00:06:27,380 That's how you do it. 111 00:06:27,380 --> 00:06:29,060 You make the parent the mine folder. 112 00:06:29,150 --> 00:06:31,130 We are going to move. 113 00:06:31,160 --> 00:06:36,500 We'll do a move to on the model level possession. 114 00:06:36,500 --> 00:06:38,750 This is the line that used to mess up. 115 00:06:38,750 --> 00:06:42,530 If you didn't have a primary part assigned, I'm pretty sure they fixed it. 116 00:06:42,530 --> 00:06:48,170 I don't know because I always assign a primary part if I use my move to All right, now we need our 117 00:06:48,170 --> 00:06:57,260 debris service and we're going to add an item which is going to be the mine and give it a variable time 118 00:06:57,260 --> 00:06:57,770 to live. 119 00:06:57,770 --> 00:07:02,140 So I'll do a random next integer. 120 00:07:02,150 --> 00:07:08,210 I'm going to give it a time to live between 3 minutes, which is 120 seconds and 5 minutes. 121 00:07:08,210 --> 00:07:08,540 Right. 122 00:07:08,540 --> 00:07:14,420 So after 5 minutes, definitely we know this mine's going to disappear, but that's okay. 123 00:07:14,420 --> 00:07:18,650 Wave loop is going to be calling this and replacing mines when we need them. 124 00:07:19,880 --> 00:07:23,750 Now let's go to our wave loop and call place mines. 125 00:07:23,750 --> 00:07:31,610 So in service, script service, we have this wave loop running and underneath above the zombies, because 126 00:07:31,610 --> 00:07:37,460 the zombies take a little bit of time, but below start wave, I'm going to get this, I'm going to 127 00:07:37,460 --> 00:07:40,370 call a utils place mines. 128 00:07:40,370 --> 00:07:45,230 We're going to need the number of mines, but we don't have that variable yet, so it's going to look 129 00:07:45,230 --> 00:07:51,980 like an error and then we're going to have the distance from the sign distance from sign, right? 130 00:07:51,980 --> 00:07:53,510 So we have two errors here. 131 00:07:53,510 --> 00:07:59,990 We need to declare these variables as local number of mines. 132 00:07:59,990 --> 00:08:01,730 How many mines should we give it? 133 00:08:01,730 --> 00:08:06,500 Oh, 15, maybe 20, maybe let's do 15. 134 00:08:07,190 --> 00:08:14,150 And then distance from sign, we'll save 50 studs. 135 00:08:14,510 --> 00:08:16,220 Let's see what that looks like. 136 00:08:17,580 --> 00:08:21,660 I'm going to put a weight underneath here, too, just to slow my loop down a little bit. 137 00:08:22,470 --> 00:08:23,260 Yeah. 138 00:08:23,280 --> 00:08:25,410 And we'll go to our world. 139 00:08:25,530 --> 00:08:27,660 We'll do a play from here. 140 00:08:28,110 --> 00:08:29,340 Let's go to home. 141 00:08:29,460 --> 00:08:30,630 Play here. 142 00:08:36,680 --> 00:08:39,560 All right, let's get our view output. 143 00:08:43,070 --> 00:08:44,450 Pretty good. 144 00:08:44,570 --> 00:08:46,670 We got some mines going. 145 00:08:46,700 --> 00:08:48,420 We have a print statement in there. 146 00:08:48,440 --> 00:08:50,540 Checking to see what the surface is. 147 00:08:50,960 --> 00:08:52,120 Let's see if these things work. 148 00:08:52,250 --> 00:08:53,750 Look at our zombies are stacking. 149 00:08:54,940 --> 00:08:56,470 You should check that out. 150 00:08:56,800 --> 00:08:58,540 Boom. 151 00:08:58,930 --> 00:08:59,920 Cool beans. 152 00:08:59,920 --> 00:09:00,310 We got. 153 00:09:00,340 --> 00:09:01,410 We got a minefield. 154 00:09:01,420 --> 00:09:04,150 Let's take a look at what it looks like in here. 155 00:09:04,150 --> 00:09:06,460 So we should have, what, 15 of these? 156 00:09:06,460 --> 00:09:09,280 And they'll replace as needed. 157 00:09:09,280 --> 00:09:14,350 They're also going to disappear after a certain period of time and then be replaced so you can get your 158 00:09:14,350 --> 00:09:16,000 zombies to come running through here. 159 00:09:16,000 --> 00:09:17,500 That'd be pretty cool.